package com.zzyl.serve.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Set;

import com.zzyl.serve.domain.Device;
import org.apache.ibatis.annotations.Select;

/**
 * 设备Mapper接口
 * 
 * @author Huanghc
 * @date 2025-08-22
 */
@Mapper
public interface DeviceMapper extends BaseMapper<Device>
{
    /**
     * 查询设备
     * 
     * @param id 设备主键
     * @return 设备
     */
    public Device selectDeviceById(Long id);

    /**
     * 查询设备列表
     * 
     * @param device 设备
     * @return 设备集合
     */
    public List<Device> selectDeviceList(Device device);

    /**
     * 新增设备
     * 
     * @param device 设备
     * @return 结果
     */
    public int insertDevice(Device device);

    /**
     * 修改设备
     * 
     * @param device 设备
     * @return 结果
     */
    public int updateDevice(Device device);

    /**
     * 删除设备
     * 
     * @param id 设备主键
     * @return 结果
     */
    public int deleteDeviceById(Long id);

    /**
     * 批量删除设备
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteDeviceByIds(Long[] ids);
    //根据设备Id直接找到老人护理员
    @Select("select ne.nursing_id from nursing_elder ne\n" +
            "        left join device d on ne.elder_id=d.binding_location\n" +
            "        where d.iot_id =#{iotId} ;")
    Set<Long> selectNurseIdsByElderIotId(String iotId);

    //根据床位，查询老人Id，再找到护理id
    @Select("select ne.nursing_id from nursing_elder ne\n" +
            "        left join elder e on ne.elder_id = e.id\n" +
            "        left join bed b on e.bed_id = b.id\n" +
            "        where bed_id = #{iotId}")
    Set<Long> selectNurseIdsByBedIotId(String iotId);
}
